	$(function(){
		//商品悬浮轮播
		//获取第一个图片路径
		var bigImgSrc =	$(".preview-list .preview-list-item:first-child").children("img").attr("src");
		$(".preview-bigimage").children("img").attr("src",bigImgSrc);
		$(".preview-list-item").mouseover(function(){
			bigImgSrc = $(this).children("img").attr("src");
			$(".preview-bigimage").children("img").attr("src",bigImgSrc);
			$(this).addClass("active").siblings().removeClass("active");
		});
		//手机专享价隐藏块显示
		$(".discounts .discounts-title").hover(
			function(){
				$(this).next().show();
			},
			function(){
				$(this).next().hide();
			}
		);
		//悬浮选择商品框改变边框样式
		$(".sku-list a").hover(function(){
			//获取类名判断是否含有 icon-chosen
			let val = $(this).children("div").children("span.icon").attr("class");
			if(val.indexOf("icon-chosen") == -1){
				$(this).children("div").attr("style","border:2px solid #FF734C;");
			}
		},function(){
			let val = $(this).children("div").children("span.icon").attr("class");
			if(val.indexOf("icon-chosen") == -1){
				$(this).children("div").attr("style","border:2px solid #ddd9d9;");
			}
		});
		//点击商品边框改变样式
		$(".sku-list a").click(function(){
			//更换对号小图标
			$(this).children("div").children("span.icon").addClass("icon-chosen");
			$(this).siblings().children("div").children("span.icon").removeClass("icon-chosen");
			//更换边框颜色
			$(this).children("div").attr("style","border:2px solid #FF734C;");
			$(this).siblings().children("div").attr("style","border:2px solid #ddd9d9;");
		});
		//侧边栏
		$(".rightBar .rightBar-list li").hover(
			function(){
				$(this).children("a").children("span").css("color","#FF734C");
				$(this).children("div").show();
			},
			function(){
				$(this).children("a").children("span").eq(0).css("color","gray");
				$(this).children("a").children("span").eq(1).css("color","rgba(35, 38, 40, 0.9)");
				$(this).children("div").hide();
			}
		);
		//点击回顶部
		$(".rightBar .rightBar-list li:last-child").click(function(){
			$(window).scrollTop(0);
			return false;
		});
		//侧边栏和内容标题鼠标滚动定位
		$(window).scroll(function(){
			let myscroll = $(this).scrollTop();
			if(myscroll>=270){
				$(".rightBar").css("position","fixed");
			}else{
				$(".rightBar").css("position","absolute");
			}
//			console.log(myscroll);
			if(myscroll>=1281){
				$(".wrap .detail").addClass("fixed");
				$(".wrap .detail-hd .fixed-group").show();
			}else{
				$(".wrap .detail-hd .fixed-group").hide();
				$(".wrap .detail").removeClass("fixed");
			}
		});
		//点击标题栏跳转
		$(".detail-hd .detail-hd-wp ul li").click(function(){
			$(this).addClass("active").siblings().removeClass("active");
			if($(window).scrollTop() >= 1280){
				$(window).scrollTop(1280);
			}
		});
		$(".detail-hd .detail-hd-wp ul li").eq(0).click(function(){
			$("#product,#comment,#question").show();
		});
		$(".detail-hd .detail-hd-wp ul li").eq(1).click(function(){
			$("#product").hide();
			$("#comment,#question").show();
		});
		$(".detail-hd .detail-hd-wp ul li").eq(2).click(function(){
			$("#product,#comment").hide();
			$("#question").show();
		});
		$(".detail-hd .detail-hd-wp ul li").eq(3).click(function(){
			$("#product,#comment,#question").hide();
		});
		//用户评价悬浮和点击图片
		$(".detail-comment-item-img.image-useless").mouseenter(function(){
			//判断大图有没有显示
			if($(this).parent().next().css("display") == "none"){
				$(this).css("cursor","zoom-in");
			}else{
				//获取当前悬浮的图片路径
				let src = $(this).children("img").attr("src");
				//获取大图的路径
				let bsrc = $(this).parent().next().children("img").attr("src");
				//判断大图是不是该src
				if(src == bsrc){
					$(this).css("cursor","zoom-out");
				}else{
					$(this).css("cursor","zoom-in");
				}
			}
		});
		//点击时
		$(".detail-comment-item-img.image-useless").click(function(){
			//点击li标签时
			//获取点击当前的路径信息
			let src = $(this).children("img").attr("src");
			//判断点击时大图是不是隐藏
			if($(this).parent().next().css("display") == "none"){
				//是隐藏  让它显示出来
				$(this).parent().next().show();
				//为大图绑定当前点击的路径
				$(this).parent().next().children("img").attr("src",src);
				$(this).css("cursor","zoom-out");
			}else{
				//大图是显示状态
				//获取正在展示大图的路径
				let dsrc = $(this).parent().next().children("img").attr("src");
				//判断当前点击的图片是不是正在展示的图片
				if(dsrc == src){
					//表示要关闭大图
					$(this).parent().next().hide();
					$(this).css("cursor","zoom-in");
				}else{
					//表示要展示当前点击的小图
					$(this).parent().next().children("img").attr("src",src);
					$(this).css("cursor","zoom-out");
				}
			}
			//判断左边有没有小图
			if($(this).index()==0){
				//alert("左边没图");
				$(".tm-m-photo-viewer-navleft").hide();
			}else{
				//alert("左边有图");
				$(".tm-m-photo-viewer-navleft").show();
			}
			//判断右边有没有小图
			if($(this)[0].nextElementSibling){
				//alert("右边有图");
				$(".tm-m-photo-viewer-navright").show();
			}else{
				//alert("右边没图");
				$(".tm-m-photo-viewer-navright").hide();
			}
		});
		//大图下鼠标手势
		$(".detail-comment-item-imgviewer.tm-m-photo-viewer").mouseenter(function(){
			$(this).children("a").css("cursor","pointer");
			$(this).children("img").css("cursor","zoom-out");
			//点击图片或者关闭大图则大图隐藏
			$(this).children("a").eq(0).click(function(){
				$(".detail-comment-item-imgviewer.tm-m-photo-viewer").hide();
				return false;
			});
			$(this).children("img").click(function(){
				$(".detail-comment-item-imgviewer.tm-m-photo-viewer").hide();
			});
		});
		//点击左边切换箭头向左切换图片
		$(".tm-m-photo-viewer-navleft").click(function(){
			leftRightTab($(this),1);
		});
		$(".tm-m-photo-viewer-navright").click(function(){
			leftRightTab($(this),2);
		});
	});
		//向左向右切换图片
		function leftRightTab(obj,num){
			//判断点击时是不是显示状态
			if($(obj).css("display") != "none"){
				//获取当前正在显示的大图路径
				let dsrc = $(obj).parent().children("img").attr("src");
				//存储索引值
				let index;
				//让大图显示为当前图片的上一张
				let len = $(obj).parent().prev().children().length;//小图片的数量
				for(let i =0;i<len;i++){
					//依次循环地找出正在显示的的索引值
					//获取每一张小图的src
					let src = $(obj).parent().prev().children("li").eq(i).children("img").attr("src");
					//判断大图路径是否与小路路径相等 如相等，留取该索引值,终止循环
					if(dsrc==src){
						index = i;
						break;
					}
				}
				//判断向左还是向右换 1：左，2：右
				if(num==1){
					//向左切换
					//获取左边图片的路径
					let lsrc = $(obj).parent().prev().children("li").eq(index-1).children("img").attr("src");
					//给大图绑定该路径信息
					$(obj).parent().children("img").attr("src",lsrc);
					//判断当前选择的图片有没有上一个
					//获取当前选择的图片父级
					let lis = $(obj).parent().prev().children("li").eq(index-1).index();
					if(lis==0){
						//说明左边没有图片了
						$(obj).hide();
					}
					//相反右边有图片
					$(obj).next().show();
				}else if(num ==2){
					//向右切换
					let rsrc = $(obj).parent().prev().children("li").eq(index+1).children("img").attr("src");
					$(obj).parent().children("img").attr("src",rsrc);
					let lis = $(obj).parent().prev().children("li").eq(index+1)[0].nextElementSibling;
					if(!lis){
						//说明没有下一个图片了
						$(obj).hide();
					}
					//相反左边有图片
					$(obj).prev().show();
				}
			}
			
		}
	$(function(){
		//鼠标悬浮购物保障改变样式切换图片
		$(".detail-service-tab ul li").eq(0).mousemove(function(){
			$(this).find(".icon.icon-service1").css("background-position","0 -136px");
			$(".icon.icon-service2").css("background-position","-1052px -136px");
			$(".icon.icon-service3").css("background-position","-1102px -136px");
			$(".icon.icon-service4").css("background-position","-952px -136px");
			$(".icon.icon-service5").css("background-position","-902px -136px");
			$(".icon.icon-service6").css("background-position","-1002px -136px");
			$(".detail-service-content").children("img").attr("src","image/commodity/server01.jpg");
		});
		$(".detail-service-tab ul li").eq(1).mousemove(function(){
			$(this).find(".icon.icon-service2").css("background-position","-200px -136px");
			$(".icon.icon-service1").css("background-position","-852px -136px");
			$(".icon.icon-service3").css("background-position","-1102px -136px");
			$(".icon.icon-service4").css("background-position","-952px -136px");
			$(".icon.icon-service5").css("background-position","-902px -136px");
			$(".icon.icon-service6").css("background-position","-1002px -136px");
			$(".detail-service-content").children("img").attr("src","image/commodity/server02.jpg");
		});
		$(".detail-service-tab ul li").eq(2).mousemove(function(){
			$(this).find(".icon.icon-service3").css("background-position","-250px -136px");
			$(".icon.icon-service1").css("background-position","-852px -136px");
			$(".icon.icon-service2").css("background-position","-1052px -136px");
			$(".icon.icon-service4").css("background-position","-952px -136px");
			$(".icon.icon-service5").css("background-position","-902px -136px");
			$(".icon.icon-service6").css("background-position","-1002px -136px");
			$(".detail-service-content").children("img").attr("src","image/commodity/server03.jpg");
		});
		$(".detail-service-tab ul li").eq(3).mousemove(function(){
			$(this).find(".icon.icon-service4").css("background-position","-100px -136px");
			$(".icon.icon-service1").css("background-position","-852px -136px");
			$(".icon.icon-service2").css("background-position","-1052px -136px");
			$(".icon.icon-service3").css("background-position","-1102px -136px");
			$(".icon.icon-service5").css("background-position","-902px -136px");
			$(".icon.icon-service6").css("background-position","-1002px -136px");
			$(".detail-service-content").children("img").attr("src","image/commodity/server04.jpg");
		});
		$(".detail-service-tab ul li").eq(4).mousemove(function(){
			$(this).find(".icon.icon-service5").css("background-position","-50px -136px");
			$(".icon.icon-service1").css("background-position","-852px -136px");
			$(".icon.icon-service2").css("background-position","-1052px -136px");
			$(".icon.icon-service3").css("background-position","-1102px -136px");
			$(".icon.icon-service4").css("background-position","-952px -136px");
			$(".icon.icon-service6").css("background-position","-1002px -136px");
			$(".detail-service-content").children("img").attr("src","image/commodity/server05.jpg");
		});
		$(".detail-service-tab ul li").eq(5).mousemove(function(){
			$(this).find(".icon.icon-service6").css("background-position","-150px -136px");
			$(".icon.icon-service1").css("background-position","-852px -136px");
			$(".icon.icon-service2").css("background-position","-1052px -136px");
			$(".icon.icon-service3").css("background-position","-1102px -136px");
			$(".icon.icon-service4").css("background-position","-952px -136px");
			$(".icon.icon-service5").css("background-position","-902px -136px");
			$(".detail-service-content").children("img").attr("src","image/commodity/server06.jpg");
		});
	});
	$(function(){
		/*
        * 商品推荐模板 父级 .recommend-list
        * <div class="recommend-item">
            <a href="#">
                <div class="recommend-item-pic">
                    <img src="image/commodity/best01.jpg"/>
                </div>
                <p class="recommend-item-name"> 花好月圆永生花台灯/红色</p>
                <p class="recommend-item-price">298</p>
            </a>
        </div>
        * 热销推荐模板 父级 .hot-list
        * <li class="hot-item">
                <a href="#">
                    <div class="hot-item-pic">
                        <img src="image/commodity/lu01.jpg"/>
                    </div>
                    <div class="hot-item-info">
                        <p class="p-title">一鹿(路)有你永生花小夜灯</p>
                        <p class="p-price rx-price">￥298</p>
                    </div>
                </a>
            </li>
        * */
		//页面加载完成后  发送ajax请求获取商品信息 添加到 商品推荐和热销推荐中
		$.post("randomCommoditys.shtml",{"number":12},function(result){
			var data = eval("("+result+")");
			for(var i=0;i<data.length;i++){
				if(i<6){
					//商品推荐部分
					$(".recommend-list").append("<div class='recommend-item'>\
                                    <a href='commodityDetails.shtml?id="+data[i].id+"'>\
                                        <div class='recommend-item-pic'>\
                                            <img src='image/commodity/"+data[i].comImage+"'/>\
                                        </div>\
                                    <p class='recommend-item-name'>"+data[i].comName+"</p>\
                                    <p class='recommend-item-price'>"+data[i].outPrice+"</p>\
                                    </a>\
                                </div>");
				}else{
					//热销推销部分
					$(".hot-list").append("<li class='hot-item'>\
                                    <a href='commodityDetails.shtml?id="+data[i].id+"'>\
                                        <div class='hot-item-pic'>\
                                        <img src='image/commodity/"+data[i].comImage+"'/>\
                                        </div>\
                                    <div class='hot-item-info'>\
                                        <p class='p-title'>"+data[i].comName+"</p>\
                                        <p class='p-price rx-price'>￥"+data[i].outPrice+"</p>\
                                    </div>\
                                </a>\
                            </li>");
				}
			}
		});
	});
